<?
function msgpop($pop){
echo "<script language=\"javascript\">" ;
echo "alert('$pop') ;" ;
echo "</script>" ;
}

function gotopage($link){
echo "<script language=\"javascript\">" ;
echo "location.href=\"$link\" ;" ;
echo "</script>" ;
}

function fenye($site,$p,$total){
$prevs = $p - 10;
if( $prevs <= 0) {
$prevs = 1;
}

$prev = $prevs - 1; 
if( $prev <= 0){
$prev = 1;
}

$nexts = $p + 9;
if( $nexts > $total) { 
$nexts = $total;
}

$next = $nexts + 1;
if( $next > $total){
$next = $total;
}

$pagenavi = "<a href=\"$site?page=1\">首頁</a>";
$pagenavi .= "&nbsp;&nbsp;";
if($p > 1){
$pagenavi.= "<a href=\"$site?page=$prev\">上頁</a>";
$pagenavi .= "&nbsp;&nbsp;";
}
//for ( $i = $prevs; $i <= $p-1; $i++ ) {
//$pagenavi.= "<a href=\"$site?page=$i\">$i</a>" ;
//}
//$pagenavi.= "<strong>$p</strong>";
//for ( $i = $p+1; $i <= $nexts; $i++ ) {
//$pagenavi.= "<a href=\"$site?page=$i\">$i</a> ";
//}
if($p < $total){
$pagenavi.= "<a href=\"$site?page=$next\">下頁</a> ";
$pagenavi .= "&nbsp;&nbsp;";
}
$pagenavi.= "<a href=\"$site?page=$total\">尾頁</a> ";

echo $pagenavi;
} 

function phpescape($str){
    preg_match_all("/[\x80-\xff].|[\x01-\x7f]+/",$str,$newstr);
    $ar = $newstr[0];
    foreach($ar as $k=>$v){
        if(ord($ar[$k])>=127){
            $tmpString=bin2hex(iconv("GBK","ucs-2",$v));
            if (!eregi("WIN",PHP_OS)){
                $tmpString = substr($tmpString,2,2).substr($tmpString,0,2);
            }
            $reString.="%u".$tmpString;
        } else {
            $reString.= rawurlencode($v);
        }
    }
    return $reString;
}

function unescape($str) { 
         $str = rawurldecode($str); 
         preg_match_all("/%u.{4}|&#x.{4};|&#d+;|.+/U",$str,$r); 
         $ar = $r[0]; 
         foreach($ar as $k=>$v) { 
                  if(substr($v,0,2) == "%u") 
                           $ar[$k] = iconv("UCS-2","GBK",pack("H4",substr($v,-4))); 
                  elseif(substr($v,0,3) == "&#x") 
                           $ar[$k] = iconv("UCS-2","GBK",pack("H4",substr($v,3,-1))); 
                  elseif(substr($v,0,2) == "&#") { 
                           $ar[$k] = iconv("UCS-2","GBK",pack("n",substr($v,2,-1))); 
                  } 
         } 
         return join("",$ar); 
} 

function del_array( $key,$value, $array) 
{
 for ($j=0; $j <= count($array);$j++){
  if ($array[$j][$key] == $value)
  {
   unset($array[$j]);
  }
 }
 sort($array); 
 Return $array;
}

function chk_array($key,$value, $array){
 for ($j=0; $j <= count($array);$j++){
  if ($array[$j][$key] == $value){
   $chk = "Y" ;
  }
 }
 Return $chk;
}

function arr_search( $array, $expression ){
    $result = array();
    $expression = preg_replace ( "/([^\s]+?)(=|<|>|!)/", "\$a['$1']$2", $expression );
    foreach ( $array as $a ) if ( eval ( "return $expression;" ) ) $result[] = $a;
    return $result;
}

function count_array($key,$array){
 for ($j=0; $j <= count($array);$j++){
  $count += $array[$j][$key] ;  
 }
 Return $count;
}

function gwSpcheck($process_time,$gwsr,$amount,$spcheck,$check_sum) {    

	$T=$process_time+$gwsr+$amount;	//算出認證用的字串
	$a = substr($T,0,1).substr($T,2,1).substr($T,4,1);//取出檢查碼的跳字組合 1,3,5 字元
	$b = substr($T,1,1).substr($T,3,1).substr($T,5,1);//取出檢查碼的跳字組合 2,4,6 字元
	$c = ( $check_sum % $T ) + $check_sum + $a + $b;//取餘數 + 檢查碼 + 奇位跳字組合 + 偶位跳字組合
		if($spcheck == $c) {
        	return '1';
    	}  else {
    		return '0';
    	}  
}
?>